﻿using Super.Admin.Global;
using System.Drawing;
using System.Windows;

namespace Super.Admin.Utils.ThemeManager
{
    /// <summary>
    /// 外观设置
    /// </summary>
    public class AppearanceSettings : ThemeViewModelBase
    {
        private Theme _theme = new Theme();
        /// <summary>
        /// 主题
        /// </summary>
        public Theme Theme
        {
            get => _theme;
            set => SetProperty(ref _theme, value);
        }
        private BuiltInThemes _builtInThemes = new BuiltInThemes();
        /// <summary>
        /// 内置颜色
        /// </summary>
        public BuiltInThemes BuiltInThemes
        {
            get => _builtInThemes;
            set => SetProperty(ref _builtInThemes, value);
        }
        private CornerRadiusType _cornerRadiusType = new CornerRadiusType();
        /// <summary>
        /// 圆角
        /// </summary>
        public CornerRadiusType CornerRadiusType
        {
            get => _cornerRadiusType;
            set => SetProperty(ref _cornerRadiusType, value);
        }
        private Other _other = new Other();
        /// <summary>
        /// 其他
        /// </summary>
        public Other Other
        {
            get => _other;
            set => SetProperty(ref _other, value);
        }
    }
    /// <summary>
    /// 主题
    /// </summary>
    public class Theme : ThemeViewModelBase
    {
        private AntdUI.TAMode _themeType = AntdUI.TAMode.Light;
        /// <summary>
        /// 主题
        /// </summary>
        public AntdUI.TAMode ThemeType
        {
            get => _themeType;
            set
            {
                SetProperty(ref _themeType, value);
            }
        }
        private bool _darkSidebar = false;
        /// <summary>
        /// 深色侧边栏
        /// </summary>
        public bool DarkSidebar
        {
            get => _darkSidebar;
            set
            {
                SetProperty(ref _darkSidebar, value);
            }
        }
        private bool _darkTopBar = false;
        /// <summary>
        /// 深色顶栏
        /// </summary>
        public bool DarkTopBar
        {
            get => _darkTopBar;
            set => SetProperty(ref _darkTopBar, value);
        }
        /// <summary>
        /// 设置主题
        /// </summary>
        /// <param name="type"></param>
        private void SetThemeType(ThemeType type)
        {
            //var dict = Application.Current.Resources.MergedDictionaries;
            //ResourceDictionary darkThemeRes = new ResourceDictionary { Source = new Uri(FilePath.DarkThemeUri, UriKind.Absolute) };
            //ResourceDictionary defualtThemeRes = new ResourceDictionary { Source = new Uri(FilePath.DefualtThemeUri, UriKind.Absolute) };
            //ResourceDictionary themeRes = new ResourceDictionary { Source = new Uri(FilePath.ThemeUri, UriKind.Absolute) };
            //if (type == ThemeType.Dark)
            //{
            //    // 查找并移除默认主题（如果存在）
            //    var defaultThemeToRemove = dict?.FirstOrDefault(d => d.Source != null && d.Source.OriginalString.Contains(FilePath.DefualtThemeUri));
            //    dict?.Remove(defaultThemeToRemove);
            //    dict?.Add(darkThemeRes);
            //}
            //else
            //{
            //    var darkThemeToRemove = dict?.FirstOrDefault(d => d.Source != null && d.Source.OriginalString.Contains(FilePath.DarkThemeUri));
            //    dict?.Remove(darkThemeToRemove);
            //    dict?.Add(defualtThemeRes);
            //}
            //var themeToRemove = dict?.FirstOrDefault(d => d.Source != null && d.Source.OriginalString.Contains(FilePath.ThemeUri));
            //dict?.Remove(themeToRemove);
            //dict?.Add(themeRes);
        }
    }
    /// <summary>
    /// 内置颜色
    /// </summary>
    public class BuiltInThemes : ThemeViewModelBase
    {
        private string _primaryColor = "#1890FF";
        /// <summary>
        /// 主色调
        /// </summary>
        public string PrimaryColor
        {
            get { return _primaryColor; }
            set
            {
                SetProperty<string>(ref _primaryColor, value);
                AntdUI.Style.Set(AntdUI.Colour.Primary, ColorTranslator.FromHtml(value));
            }
        }
        private string _warningColor = "#FAAD14";
        /// <summary>
        /// 警告色
        /// </summary>
        public string WarningColor
        {
            get { return _warningColor; }
            set
            {
                SetProperty<string>(ref _warningColor, value);
                AntdUI.Style.Set(AntdUI.Colour.Warning, ColorTranslator.FromHtml(value));
            }
        }
        private string _infoColor = "#1890FF";
        /// <summary>
        /// 信息色
        /// </summary>
        public string InfoColor
        {
            get { return _infoColor; }
            set
            {
                SetProperty<string>(ref _infoColor, value);
                AntdUI.Style.Set(AntdUI.Colour.Info, ColorTranslator.FromHtml(value));
            }
        }
        private string _errorColor = "#FF4D4F";
        /// <summary>
        /// 错误色
        /// </summary>
        public string ErrorColor
        {
            get { return _errorColor; }
            set
            {
                SetProperty<string>(ref _errorColor, value);
                AntdUI.Style.Set(AntdUI.Colour.Error, ColorTranslator.FromHtml(value));
            }
        }
        private string _successColor = "#52C41A";
        /// <summary>
        /// 成功色
        /// </summary>
        public string SuccessColor
        {
            get { return _successColor; }
            set
            {
                SetProperty<string>(ref _successColor, value);
                AntdUI.Style.Set(AntdUI.Colour.Success, ColorTranslator.FromHtml(value));
            }
        }
    }
    /// <summary>
    /// 圆角
    /// </summary>
    public class CornerRadiusType : ThemeViewModelBase
    {
        private int _cornerRadius = 5;
        /// <summary>
        /// 圆角
        /// </summary>
        public int CornerRadius
        {
            get => _cornerRadius;
            set
            {
                SetProperty(ref _cornerRadius, value);
                foreach (Form form in Application.OpenForms)
                {
                    if (form is Views.Base.BaseForm baseForm)
                    {
                        baseForm.RefreshCornerRadius(form,value);
                    }
                }
            }
        }
    }
    /// <summary>
    /// 其他
    /// </summary>
    public class Other : ThemeViewModelBase
    {
        private bool _colorWeaknessMode = false;
        /// <summary>
        /// 色弱模式
        /// </summary>
        public bool ColorWeaknessMode
        {
            get => _colorWeaknessMode;
            set => SetProperty(ref _colorWeaknessMode, value);
        }
        private bool _greyMode = false;
        /// <summary>
        /// 灰色模式
        /// </summary>
        public bool GreyMode
        {
            get => _greyMode;
            set => SetProperty(ref _greyMode, value);
        }
    }
    /// <summary>
    /// 主题类型
    /// </summary>
    public enum ThemeType
    {
        Light = 0,
        Dark = 1,
    }
}
